package com.csun.cmny.provider.manager;

import com.csun.cmny.provider.model.domain.UacAddress;
import com.csun.cmny.provider.model.domain.UacUser;
import com.csun.cmny.provider.service.UacAddressService;
import com.csun.cmny.util.RedisKeyUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class AddressManager {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Resource
    private UacAddressService addressService;

    //将地址信息写入到定时任务
    @Scheduled(cron = "0 0 2 * * ?")
    public void selectUserNameByUserId() {

        List<UacAddress> uacAddresses = addressService.selectAll();

        for (UacAddress uacAddress : uacAddresses) {

            String redisKey = RedisKeyUtil.getUacAddress(uacAddress.getId().toString());

            //写入地址信息
            redisTemplate.opsForValue().set(redisKey,uacAddress);

        }
    }
}
